//
//  JSFormFooterView.swift
//  fho
//
//  Created by 郭颢源 on 2021/4/25.
//

import UIKit

let JSFormFooterViewID : String = "JSFormFooterView"

class JSFormFooterView: UITableViewHeaderFooterView {
    
    var  textClor : UIColor = .white
    var  textFont : UIFont = UIFont.systemFont(ofSize: 15.0)
    
    var  iconBtnImageWidth : CGFloat {
        return (self.iconBtn.currentImage?.size.width)!
    }
    var  iconBtnImageHeight : CGFloat {
        get{
            return (self.iconBtn.currentImage?.size.height)!
        }
    }
    var  cellMargin : CGFloat = 15.0
    //    var  model : JSFormModel = JSFormModel(){
    //        didSet{
    //            let iconImage:UIImage = (model.icon.count > 0 ? UIImage(named: model.icon):nil)!
    //            self.iconBtn.setImage(iconImage, for: .normal)
    //            self.iconBtn.setTitle(model.name, for: .normal)
    //        }
    //    }
    
    
    lazy var iconBtn:UIButton = {
        var _iconBtn = UIButton()
        _iconBtn.titleLabel!.font = self.textFont
        _iconBtn.titleEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
        _iconBtn.contentHorizontalAlignment = .center
        _iconBtn.setTitleColor(self.textClor, for: .normal)
        _iconBtn.setTitle("确定", for: .normal)
        _iconBtn.backgroundColor = .systemOrange
        _iconBtn.addTarget(self, action: #selector(click(_:)), for: .touchUpInside)
        return _iconBtn
    }()
    
    typealias clickBlock = (_ str:String)->Void
    var block : clickBlock?
    @objc func click(_ sender : UIButton){
        block!("")
    }
    
    override init(reuseIdentifier: String?) {
        super.init(reuseIdentifier: reuseIdentifier)
        contentView.backgroundColor = .systemGray6
        contentView.addSubview(iconBtn)
        
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        
        iconBtn.snp.makeConstraints { (make) in
            make.top.equalTo(contentView).offset(-5)
            make.right.equalToSuperview().offset(-40)
            make.width.equalTo(80)
            make.height.equalTo(40)
        }
        
        iconBtn.sg_addCorner(radius: 20.0)
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    /*
     // Only override draw() if you perform custom drawing.
     // An empty implementation adversely affects performance during animation.
     override func draw(_ rect: CGRect) {
     // Drawing code
     }
     */
    
}
